package com.youlian.cloud.core.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.context.event.ContextStoppedEvent;

import java.util.concurrent.TimeUnit;

/**
 * @author liuhx
 * @create 2019/07/29 15:41
 * @email liuhx@elab-plus.com
 **/
public class ApplicationEventListener implements ApplicationListener<ApplicationEvent> {
    private static Logger LOGGER = LoggerFactory.getLogger(ApplicationEventListener.class);

    public ApplicationEventListener() {
    }

    @Override
    public void onApplicationEvent(ApplicationEvent event) {
//        try {
//            if (event instanceof ApplicationEnvironmentPreparedEvent) {
//                LOGGER.info("ApplicationEnvironmentPreparedEvent 初始化环境变量");
//            } else if (event instanceof ApplicationPreparedEvent) {
//                LOGGER.info("ApplicationPreparedEvent 初始化完成");
//            } else if (event instanceof ContextRefreshedEvent) {
//                LOGGER.info("ContextRefreshedEvent  应用刷新");
//            } else if (event instanceof ApplicationReadyEvent) {
//                LOGGER.info("ApplicationReadyEvent 应用已启动完成");
//            } else if (event instanceof ContextStartedEvent) {
//                LOGGER.info("ContextStartedEvent 应用启动");
//            } else if (event instanceof ContextStoppedEvent) {
//                LOGGER.info("ContextStoppedEvent 应用停止");
//                TimeUnit.SECONDS.sleep(1L);
//                System.out.println("application startup failed");
//                TimeUnit.SECONDS.sleep(1L);
//            } else if (event instanceof ContextClosedEvent) {
//                LOGGER.info("ContextClosedEvent 应用关闭");
//                TimeUnit.SECONDS.sleep(1L);
//                System.out.println("application startup failed");
//                TimeUnit.SECONDS.sleep(1L);
//            }
//        } catch (Exception var3) {
//
//        }

    }
}
